package JDBC;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import Model.Lieu;


public class Lieu_Ajouter {


	public void ajouter(Lieu mat) {

		try {	

			connexionBDD a = new connexionBDD();
			Connection conn=a.connect();

			Statement state = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

			Statement state1 = conn.createStatement();
			ResultSet result = state1.executeQuery("Select MAX(id_lieu) from lieu");
						
			int idp=0;
			
			try{
				while(result.next()){
					idp=Integer.parseInt(result.getObject(1).toString())+1;
				}
			}
			catch(Exception e){		
			}
			
			result.close();
			
			
		/*	int idd=1;
			
			try
			{
				while(result2.next())
				{
					idd=Integer.parseInt(result.getObject(7).toString())+1;
				}
			}
			catch(Exception e)
			{		
			}
			
			result2.close();*/
			

			state.executeUpdate("INSERT INTO Lieu VALUES ("+idp+","
			+mat.getNumero()+",'"
			+mat.getRue()+"','"
			+mat.getComplement()+"',"
			+mat.getCp()+",'"
			+mat.getVille()+"',"
			+1+");");	


			state.close();
			
		} 

		catch (Exception e) {
			e.printStackTrace();
		}	

	}

}
